<?php

namespace App\Admin\Repositories;

use App\Models\TodoTask as Model;
use Dcat\Admin\Repositories\EloquentRepository;

class TodoTask extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    public function getById($id)
    {
        $ret = $this->eloquentClass::query()->where('todo_id', $id)->first();

        if ($ret) {
            return $ret->toArray();
        } else {
            return [];
        }
    }

    public function quickAdd(string $taskName, int $creatorUid) : bool
    {
        return $this->eloquentClass::query()
            ->insert(['task_name' => $taskName, 'creator_uid' => $creatorUid]);
    }

    public function upd(int $todoId, array $data) : bool
    {
        return $this->eloquentClass::query()
            ->where('todo_id', $todoId)
            ->update($data);
    }
}
